package com.itany.ems.service.impl;

import com.itany.ems.dao.EmpDao;
import com.itany.ems.dao.impl.EmpDaoImpl;
import com.itany.ems.entity.Emp;
import com.itany.ems.exception.DataAccessException;
import com.itany.ems.exception.RequestParameterErrorException;
import com.itany.ems.exception.ServiceException;
import com.itany.ems.service.EmpService;
import com.itany.ems.util.ParameterUtil;

/**
 * @author 石小俊
 * @date 2024年05月24日 18:49
 */
public class EmpServiceImpl implements EmpService {

    private EmpDao empDao = new EmpDaoImpl();

    @Override
    public void addEmp(String name, String salary, String gender, String edu, String[] hobbies) throws RequestParameterErrorException, ServiceException {
        if(ParameterUtil.isNull(name) || ParameterUtil.isNull(salary) || ParameterUtil.isNull(gender) || ParameterUtil.isNull(edu) || hobbies == null){
            throw new RequestParameterErrorException("请求参数有误");
        }
        Emp emp = new Emp(name,Double.parseDouble(salary),gender,edu,hobbies);
        try {
            empDao.insertEmp(emp);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw new ServiceException(e.getMessage());
        }
    }
}
